public class Solution1095 {

    static class MountainArray {

        int[] arr=new int[]{3,5,3,2,0};
        int time=0;

        public int get(int index) {
            time++;
            if (time>100){
                System.out.println("fail");
            }
            return arr[index];
        }

        public int length() {
            return arr.length;
        }
    }

    public int findInMountainArray(int target, MountainArray mountainArr) {
        int l=1,r=mountainArr.length()-2;
        int ans=-1;
        while (l<=r){
            int mid=(l+r)/2;
            int t=mountainArr.get(mid);
            int t1=mountainArr.get(mid-1);
            int t2=mountainArr.get(mid+1);
            if (t>t1 && t>t2){
                ans=mid;
                break;
            }else if (t>t1 && t2>t){
                l=mid+1;
            }else{
                r=mid-1;
            }
        }
        l=0;
        r=ans;
        while (l<=r){
            int mid=(l+r)/2;
            int t=mountainArr.get(mid);
            if (t==target){
                return mid;
            }else if (t>target){
                r=mid-1;
            }else{
                l=mid+1;
            }
        }
        l=ans+1;
        r=mountainArr.length()-1;
        while (l<=r){
            int mid=(l+r)/2;
            int t=mountainArr.get(mid);
            if (t==target){
                return mid;
            }else if (t>target){
                l=mid+1;
            }else{
                r=mid-1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1095().findInMountainArray(0,new MountainArray()));
    }
}
